var songlist,playlist,recentplay,othersaves={};
function load()
{
	if(localStorage.arcothersaves!=undefined) othersaves=JSON.parse(Base64.decode(localStorage.arcothersaves));
	if(localStorage.arcsave!=undefined)
	{
		var t=JSON.parse(Base64.decode(localStorage.arcsave));
		recentplay=t.recentplay;
		playlist=t.playlist;
		songlist=t.songlist;
	}
	else
	{
		if(localStorage.songlist==undefined) songlist={};
		else songlist=JSON.parse(Base64.decode(localStorage.songlist));
		if(localStorage.playlist==undefined) playlist=[];
		else playlist=JSON.parse(Base64.decode(localStorage.playlist));
		if(localStorage.recentplay==undefined) recentplay={};
		else recentplay=JSON.parse(Base64.decode(localStorage.recentplay));
		localStorage.removeItem('songlist');
		localStorage.removeItem('playlist');
		localStorage.removeItem('recentplay');
	}
	if(songlist==undefined) songlist={};
	if(playlist==undefined) playlist=[];
	if(recentplay==undefined) recentplay={};
	save();
}
function save()
{
	localStorage.arcsave=Base64.encode(JSON.stringify({songlist:songlist,playlist:playlist,recentplay:recentplay}));
	localStorage.arcothersaves=Base64.encode(JSON.stringify(othersaves));
}
function outersave()
{
	document.getElementById('rawoutput').value=Base64.encode(JSON.stringify({songlist:songlist,playlist:playlist,recentplay:recentplay}));
}
function outerload()
{
	var r=confirm('确定导入吗？这会覆盖你当前的存档！\n建议提前导出当前存档再导入！');
	if(!r) return;
	var t=JSON.parse(Base64.decode(document.getElementById('rawinput').value));
	recentplay=t.recentplay;
	playlist=t.playlist;
	songlist=t.songlist;
	if(recentplay==undefined) recentplay={};
	if(playlist==undefined) playlist=[];
	if(songlist==undefined) songlist={};
	save();show();
	alert('导入成功。')
}
function clearsave()
{
	var r=confirm('确定清空存档吗？这会清除所有游玩信息和所有曲目信息！\n建议仅在存档损坏时使用！');
	if(!r)return;
	r=confirm('请再次确认是否清空存档，这会删除所有存储信息！');
	if(!r)return;
	r=confirm('存档被清空后无法被直接恢复（除非提前导出），请最后确认是否清空存档！');
	if(!r)return;
	songlist={};playlist=[];recentplay={};
	save();show();
	alert('存档已经清空。')
}
function innersave()
{
	var slotname=document.getElementById('slot').value;
	if(othersaves[slotname]!=undefined)
	{
		var r=confirm('存档位 '+slotname+' 已有存档，确定将其覆盖吗？');
		if(!r) return;
	}
	othersaves[slotname]=Base64.encode(JSON.stringify({songlist:songlist,playlist:playlist,recentplay:recentplay}));
	save();show();
}
function innerload()
{
	var slotname=document.getElementById('slot').value;
	if(othersaves[slotname]==undefined)
	{
		alert('存档位 '+slotname+' 不存在，请检查名称是否输入错误。');
		return;
	}
	var r=confirm('确定导入吗？这会覆盖你当前的存档！\n建议提前导出当前存档再导入！');
	if(!r)return;
	var t=JSON.parse(Base64.decode(othersaves[slotname]));
	recentplay=t.recentplay;
	playlist=t.playlist;
	songlist=t.songlist;
	save();show();
}
function innerdel()
{
	var slotname=document.getElementById('slot').value;
	if(othersaves[slotname]==undefined)
	{
		alert('存档位 '+slotname+' 不存在，请检查名称是否输入错误。');
		return;
	}
	var r=confirm('确定删除此存档位吗？这会使你失去此存档位保存的内容！');
	if(!r)return;
	delete othersaves[slotname];
	save();show();
}